package com.gae.tutorial;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.repackaged.org.apache.commons.logging.Log;
import com.google.appengine.repackaged.org.apache.commons.logging.LogFactory;

@SuppressWarnings("serial")
public class GaeLogServlet extends HttpServlet {
	
	private static Log log = LogFactory.getLog(GaeLogServlet.class);
	 
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		
		
		String level =  req.getParameter("level");
		String valor =  req.getParameter("valor");
		
		
		resp.setContentType("text/plain");
		
		try{
			
			if(level.equalsIgnoreCase("STD")){
				System.out.println(valor);
			}
			if(level.equalsIgnoreCase("DEBUG")){
				log.debug(valor);
			}
			if(level.equalsIgnoreCase("INFO")){
				log.info(valor);
			}
			if(level.equalsIgnoreCase("WARN")){
				log.warn(valor);
			}
			if(level.equalsIgnoreCase("ERROR")){
				log.error(valor);
			}

			resp.getWriter().println("OK");
		} catch(Exception ex){
			
			System.out.println("Error");

			resp.getWriter().println("Error");
		}
		
		
	}
}
